package com.lizard.schedule.service.base;

import android.app.Service;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.IBinder;

import com.lizard.schedule.log.ScheduleLog;

/**
 * Service 基础类
 */
public class BaseService extends Service {

    private final String TAG = getClass().getSimpleName();

    private final String TAG_LIFE = TAG + " life";

    /**
     * activity 生命周期log是否打印
     */
    private final boolean mLiftLogAble = true;

    @Override
    public void onDestroy() {
        super.onDestroy();
        logLife("onDestroy()");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        logLife("onStartCommand(Intent intent, int flags, int startId)");
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onCreate() {
        logLife("onCreate()");
        super.onCreate();
    }

    @Override
    public boolean onUnbind(Intent intent) {
        logLife("onUnbind(Intent intent)");
        return super.onUnbind(intent);
    }

    @Override
    public void onRebind(Intent intent) {
        logLife("onRebind(Intent intent)");
        super.onRebind(intent);
    }

    @Override
    public IBinder onBind(Intent intent) {
        logLife("onBind(Intent intent)");
        return null;
    }

    @Override
    public void onTrimMemory(int level) {
        logLife("onTrimMemory(int level)");
        super.onTrimMemory(level);
    }

    @Override
    public void onLowMemory() {
        logLife("onLowMemory()");
        super.onLowMemory();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        logLife("onConfigurationChanged(Configuration newConfig)");
        super.onConfigurationChanged(newConfig);
    }

    @Override
    public void onTaskRemoved(Intent rootIntent) {
        logLife("onTaskRemoved(Intent rootIntent)");
        super.onTaskRemoved(rootIntent);
    }

    /**
     * 生命周期log输出
     */
    private void logLife(String actLife){
        if(mLiftLogAble){
            ScheduleLog.v(TAG_LIFE, actLife);
        }
    }
}
